/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.dao;

import br.com.deployment.daogenerico.DaoGenerico;
import br.com.deployment.entidade.selo.CorSelo;
import br.com.deployment.interfaces.CorSeloDaoIn;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author luciano
 */
@Stateless
@LocalBean
public class CorSeloDao extends DaoGenerico<CorSelo> implements CorSeloDaoIn{
    
    public CorSeloDao(){
        super(CorSelo.class);
    }
    
    @Override
    public CorSelo findNome(String nome) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    @Override
    public List<CorSelo> findCorSelo(CorSelo corSelo) {
        List<CorSelo> listCor = new ArrayList<CorSelo>();
        if(corSelo != null){
             String sql = "Select c from CorSelo c where ";
             
             if(corSelo.getDescricao()!= null && corSelo.getDescricao() != ""){
                 sql += " lower(c.descricao) like lower(?1)"; 
             }
             Query query = getEm().createQuery(sql);
             if(corSelo.getDescricao()!= null && corSelo.getDescricao() != ""){
                 query.setParameter("1", "%" + corSelo.getDescricao() + "%");
             }
        
              listCor = query.getResultList();
              System.out.println(sql);
        }
        
        return listCor;
    }    
}
